package com.ruoyi.teacher.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.FlowProcDefDto;
import com.ruoyi.teacher.domain.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teacher.service.ITeacherService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教师基本信息Controller
 *
 * @author Mie
 * @date 2022-04-12
 */
@Api(tags = "教师管理")
@RestController
@RequestMapping("/teacher/person")
public class TeacherController extends BaseController
{
    @Autowired
    private ITeacherService teacherService;

    /**
     * 查询教师基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('teacher:person:list')")
    @GetMapping("/list")
    public TableDataInfo list(Teacher teacher)
    {
        startPage();
        List<Teacher> list = teacherService.selectTeacherList(teacher);
        return getDataTable(list);
    }

    /**
     * 查询指定部门下的教师列表
     */
    @ApiOperation(value = "查询指定部门下的教师列表")
    @PostMapping("/{deptIds}")
    public TableDataInfo listTeacherByDeptIds(@PathVariable Long[] deptIds,Integer pageNum,Integer pageSize) {
        startPage(pageNum,pageSize);
        List<Teacher> list = teacherService.listTeacherByDeptIds(deptIds);
        logger.info("指定部门{}查询出的教师列表为{}",deptIds,list);
        return getDataTable(list);
    }

    /**
     * 查询教师教师列表
     */
    @ApiOperation(value = "查询教师教师列表")
    @GetMapping("/selectListNoParamaters")
    public List<Teacher> selectListNoParamaters() {
        List<Teacher> teachers = teacherService.selectListNoParamaters();
        logger.info("查询教师教师列表为{}",teachers);
        return teachers;
    }
    /**
     * 查询教师各年龄段的人数
     */
    @ApiOperation(value = "查询教师各年龄段的人数")
    @GetMapping("/selectCount")
    public AjaxResult selectCount() {
        List<Integer> numbers = teacherService.selectCount();
        logger.info("查询教师各年龄段的人数为{}",numbers);
        return AjaxResult.success(numbers);
    }

    /**
     * 通过A00查询教师的学历学位信息
     */
    @ApiOperation(value = "通过A00查询教师的学历学位信息")
    @GetMapping("/selectDegreeByA00")
    public TableDataInfo selectDegreeByA00(@RequestParam Long A00) {
        List<Degree> degrees = teacherService.selectDegreeByA00(A00);
        logger.info("通过A00查询教师的学历学位信息为{}",degrees);
        return getDataTable(degrees);
    }

    /**
     * 通过A00查询教师的工作信息
     */
    @ApiOperation(value = "通过A00查询教师的工作信息")
    @GetMapping("/selectWorkInfoByA00")
    public TableDataInfo selectWorkInfoByA00(@RequestParam Long A00) {
        List<TWork> tWorks = teacherService.selectWorkInfoByA00(A00);
        logger.info("通过A00查询教师的工作信息为{}",tWorks);
        return getDataTable(tWorks);
    }

    /**
     * 通过A00查询教师的职称信息
     */
    @ApiOperation(value = "通过A00查询教师的职称信息")
    @GetMapping("/selectTitleByA00")
    public TableDataInfo selectTitleByA00(@RequestParam Long A00) {
        List<TTitle> tTitles = teacherService.selectTitleByA00(A00);
        logger.info("通过A00查询教师的职称信息为{}",tTitles);
        return getDataTable(tTitles);
    }

    /**
     * 通过A00查询教师的培训情况
     */
    @ApiOperation(value = "通过A00查询教师的培训情况")
    @GetMapping("/selectTrainByA00")
    public TableDataInfo selectTrainByA00(@RequestParam Long A00) {
        List<TTrain> tTrains = teacherService.selectTrainByA00(A00);
        logger.info("通过A00查询教师的培训情况为{}",tTrains);
        return getDataTable(tTrains);
    }

    /**
     * 通过A00查询教师的考核信息
     */
    @ApiOperation(value = "通过A00查询教师的考核信息")
    @GetMapping("/selectAssessmentByA00")
    public TableDataInfo selectAssessmentByA00(@RequestParam Long A00) {
        List<TAssessment> tAssessments = teacherService.selectAssessmentByA00(A00);
        logger.info("通过A00查询教师的考核信息为{}",tAssessments);
        return getDataTable(tAssessments);
    }

    /**
     * 通过A00查询教师的档案信息
     */
    @ApiOperation(value = "通过A00查询教师的档案信息")
    @GetMapping("/selectFileByA00")
    public TableDataInfo selectFileByA00(@RequestParam Long A00) {
        List<TFile> tFiles = teacherService.selectFileByA00(A00);
        logger.info("通过A00查询教师的档案信息为{}",tFiles);
        return getDataTable(tFiles);
    }

    /**
     * 通过A00查询教师的附件材料
     */
    @ApiOperation(value = "通过A00查询教师的附件材料")
    @GetMapping("/selectAppendixByA00")
    public TableDataInfo selectAppendixByA00(@RequestParam Long A00) {
        List<TAppendix> tAppendices = teacherService.selectAppendixByA00(A00);
        logger.info("通过A00查询教师的附件材料为{}",tAppendices);
        return getDataTable(tAppendices);
    }

    /**
     * 根据A00查询教师教师列表
     */
    @ApiOperation(value = "根据A00查询教师教师列表")
    @GetMapping("/selectListByA00")
    public TableDataInfo selectListByA00(@RequestParam Long A00) {
        List<Teacher> teachers = teacherService.selectListByA00(A00);
        logger.info("根据A00查询教师教师列表{}",teachers);
        return getDataTable(teachers);
    }

    /**
     * 导出教师本人基本信息
     */
    @ApiOperation(value = "根据A00导出个人基本信息")
    @Log(title = "教师本人基本信息")
    @GetMapping("/exportSelf")
    public AjaxResult exportSelf(@RequestParam Long A00)
    {
        List<Teacher> list = teacherService.selectListByA00(A00);
        ExcelUtil<Teacher> util = new ExcelUtil<Teacher>(Teacher.class);
        return util.exportExcel(list, "person");
    }

    /**
     * 导出教师基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('teacher:person:export')")
    @Log(title = "教师基本信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Teacher teacher)
    {
        List<Teacher> list = teacherService.selectTeacherList(teacher);
        ExcelUtil<Teacher> util = new ExcelUtil<Teacher>(Teacher.class);
        return util.exportExcel(list, "person");
    }

    /**
     * 通过A00获取教师基本信息
     */
    @ApiOperation(value = "通过A00获取教师基本信息")
    @PreAuthorize("@ss.hasPermi('teacher:person:query')")
    @GetMapping(value = "/getTeacherInfoByA00")
    public AjaxResult getInfoByA00(@RequestParam(value = "A00") Long A00)
    {
        Teacher teacher = teacherService.selectTeacherByA00(A00);
        logger.info("通过A00获取教师基本信息为{}",teacher);
        return AjaxResult.success(teacher);
    }

    /**
     * 通过userId获取教师基本信息
     */
    @ApiOperation(value = "通过userId获取教师基本信息")
    @PreAuthorize("@ss.hasPermi('teacher:person:query')")
    @GetMapping(value = "/getTeacherInfo")
    public AjaxResult getInfoByUserId(@RequestParam(value = "userId") Long userId)
    {
        Teacher teacher = teacherService.selectTeacherByUserId(userId);
        logger.info("通过userId获取教师基本信息为{}",teacher);
        return AjaxResult.success(teacher);
    }

    /**
     * 获取教师基本信息详细信息
     */
    @ApiOperation(value = "获取教师基本信息详细信息A00")
    @PreAuthorize("@ss.hasPermi('teacher:person:query')")
    @GetMapping(value = "/{a00}")
    public AjaxResult getInfo(@PathVariable("a00") Long a00)
    {
        return AjaxResult.success(teacherService.selectTeacherById(a00));
    }

    /**
     * 新增教师基本信息
     */
    @PreAuthorize("@ss.hasPermi('teacher:person:add')")
    @Log(title = "教师基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Teacher teacher)
    {
        return toAjax(teacherService.insertTeacher(teacher));
    }

    /**
     * 修改教师基本信息
     */
    @PreAuthorize("@ss.hasPermi('teacher:person:edit')")
    @Log(title = "教师基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Teacher teacher)
    {
        return toAjax(teacherService.updateTeacher(teacher));
    }

    /**
     * 删除教师基本信息
     */
    @PreAuthorize("@ss.hasPermi('teacher:person:remove')")
    @Log(title = "教师基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{a00s}")
    public AjaxResult remove(@PathVariable Long[] a00s)
    {
        return toAjax(teacherService.deleteTeacherByIds(a00s));
    }
}
